import express from 'express';
import { authRouter, verifyToken } from './modules/auth.js';
import userRouter from './modules/user.js';

const app = express();
const port = 9999;

// 解析 JSON 请求体
app.use(express.json());   

// 处理预检请求，避免 Network 面板报红（跨域场景兜底）
app.options(/(.*)/, (req, res) => {
  res.status(200).set({
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Headers': 'content-type, authorization',
    'Access-Control-Allow-Methods': 'POST, OPTIONS'
  }).end();
});



// 挂载用户路由
app.use('/user', verifyToken, userRouter);
// app.use('/user', userRouter);
app.use('/auth', authRouter);

app.listen(port, () => {
  console.log(`Mock server running at http://localhost:${port}`);
});

